<?php
	header("Content-type: text/html;charset=utf8");
	require_once("../db/dbclass.php");
	require_once("../model/userinfo.php");
	require_once("../utils/common.php");
	$myDb=&DbController::getInstance();
	$username=$_POST['user_name'];
	$password=$_POST['user_password'];
	$param="select * from yj_user_info where user_name ='".$username."' and user_password ='".$password."'";
	$result_count = mysqli_num_rows($myDb->exec_query($param));
	$result_obj = new UserSign();
	if($result_count != 0){
		$result = $myDb->exec_query($param);
		if($result == TRUE){
			$row = mysqli_fetch_array($result,MYSQL_ASSOC);
			$param="INSERT INTO yj_login_record (user_id, login_time, login_ip) VALUES ('".$row['user_id']."','".date('y-m-d h:i:s',time())."','".getIp()."')";
			$result_insert = $myDb->exec_query($param);
			if($result_insert==TRUE){
		  		$result_obj->id = $row['user_id'];
		  		$result_obj->username = $row['user_name'];
		  		$result_obj->email = $row['user_email'];
		  		$result_obj->result = "success";
			}
			else{
				$result_obj->result = "fail_serverbusy";
			}
		}
		else{
			$result_obj->result = "fail_serverbusy";
		}
	}
	else{
		$result_obj->result = "failure";
	}
	$result_json = json_encode($result_obj);
	echo $result_json;
?>